package com.harmonyos.cases.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class HtmlParse {

    /**
     * 从HTML字符串中提取指定标签下的文字内容
     *
     * @param html    HTML字符串
     * @param tagName 标签名
     * @return 标签下的文字内容
     */
    public static String getTextFromTag(String html, String tagName) {
        if (html == null || html.isEmpty() || tagName == null || tagName.isEmpty()) {
            return "";
        }

        Document document = Jsoup.parse(html);
        Elements elements = document.select(tagName);

        StringBuilder textContent = new StringBuilder();
        for (Element element : elements) {
            if (element.attr("name").equals("blob_raw") && element.attr("id").equals("blob_raw")) {
                textContent.append(element.text());
            }
        }

        return textContent.toString().trim();
    }

}
